package com.ruoyi.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.dto.ResponseDTO;
import com.ruoyi.pojo.TOrderDo;
import com.ruoyi.service.IOrderService;
import com.ruoyi.vo.OrderQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

/**
* @Description:订单管理
* @Param:
* @Return:
*/
@RestController
@RequestMapping("order")
public class OrderController extends BaseController {

    @Autowired
    private IOrderService orderService;

    /**
    * @Description:获取全部订单列表
    * @Param:
    * @Return:
    */
    @RequestMapping("getAllOrderList")
    public TableDataInfo getAllOrderList(OrderQueryVo orderQueryVo){
        startPage();
        List<TOrderDo> allOrderList = orderService.getAllOrderList(orderQueryVo);
        return getDataTable(allOrderList);
    }

    /**
    * @Description:新增订单
    * @Param:
    * @Return:
    */
    @Log(title = "订单管理" ,businessType = BusinessType.INSERT)
    @RequestMapping("addOrder")
    public AjaxResult addOrder(TOrderDo tOrderDo){
        return toAjax(orderService.addOrder(tOrderDo));
    }

    /**
     * @Description:修改订单
     * @Param:
     * @Return:
     */
    @Log(title = "订单管理" ,businessType = BusinessType.UPDATE)
    @PutMapping("updateTOrder")
    public AjaxResult updateTOrder(@RequestBody TOrderDo tOrderDo){
        System.out.println(tOrderDo.getCreateBy());
        System.out.println(tOrderDo.getRemark());
        System.out.println(tOrderDo.getUpdateBy());
        return toAjax(orderService.updateTOrder(tOrderDo));
    }

    /**
     * @Description:删除订单
     * @Param:
     * @Return:
     */
    @Log(title = "订单管理" ,businessType = BusinessType.DELETE)
    @DeleteMapping("deleteTOrderById")
    public AjaxResult deleteTOrderById(@RequestParam Long id){
        return toAjax(orderService.deleteTOrderById(id));
    }

    /**
     * @Description:订单详情
     * @Param:
     * @Return:
     */
    @RequestMapping("selectTOrderVo")
    public AjaxResult selectTOrderVo(@RequestParam Long id){
        return success(orderService.selectTOrderVo(id));
    }

    /**
     * @Description:批量删除订单
     * @Param:
     * @Return:
     */
    @Log(title = "订单管理" ,businessType = BusinessType.DELETE)
    @DeleteMapping("deleteTOrderByIds")
    public AjaxResult deleteTOrderByIds(@RequestBody Long[] ids){
       return toAjax(orderService.deleteTOrderByIds(ids));
    }


    /**
     * @Description:通过Id指定字段名查询订单数据
     * @Param:
     * @Return:
     */
    @RequestMapping("selectOrderVoById")
    public TableDataInfo selectOrderVoById(@RequestParam("id") Long id, @RequestParam("field")String field){
        startPage();
        List<TOrderDo> tOrderDos = orderService.selectOrderVoById(id, field);
        return getDataTable(tOrderDos);
    }

}
